﻿using AdminStyem.Application.Command.CultivationCommand;
using AdminStyem.Domain.Entity.Boss;
using AdminStyem.Repositories;
using AutoMapper;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminStyem.Application.CommandHandler.CultivatioHandler
{
    public class BreedingAddCommandHandler : IRequestHandler<BreedingAddCommand, APIResult<object>>
    {
        IBaseRespository<BreedBass> BaseBreed;
        IMapper mapper;

        public BreedingAddCommandHandler(IMapper mapper, IBaseRespository<BreedBass> BaseBreed)
        {
            this.mapper = mapper;
            this.BaseBreed = BaseBreed;
        }

        public Task<APIResult<object>> Handle(BreedingAddCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> ret = new APIResult<object>();
            ret.Code = ResultCode.添加成功;
            ret.Message=ResultCode.添加成功.ToString();
            var data = mapper.Map<BreedBass>(request);
           int i= BaseBreed.add(data).Result;
            if (i <= 0)
            {
                ret.Code = ResultCode.添加失败;
                ret.Message = ResultCode.添加失败.ToString();
                return Task.FromResult(ret);
            }
            return Task.FromResult(ret);
        }
    }
}
